<?php
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Worker\Model;
use Think\Model;

/**
 * 用户模型
 * @author derek <693472824@qq.com>
 */
class WorkerModel extends Model {

    protected $_validate = array(
        
        /* 验证密码 */
        array('repassword', 'password', '确认密码与密码不同', self::EXISTS_VALIDATE, 'confirm', 4), 
        array('password', '6,30', '密码长度不符合规范', self::VALUE_VALIDATE, 'length'), 
            
        /* 验证手机号码 */
        array('account', 'require', '手机号码不能为空', self::VALUE_VALIDATE, self::MODEL_INSERT),
        array('account', 'checkMobile', '手机号码格式不正确', self::VALUE_VALIDATE, 'callback', self::MODEL_INSERT), //手机格式不正确 
        array('account', '', '手机号码已被占用', self::VALUE_VALIDATE, 'unique', self::MODEL_INSERT), //手机号被占用
        
    );

    /**
     * 用户模型自动完成
     */
	protected $_auto = array(
		array('password', '', self::MODEL_BOTH, 'ignore'),
		array('password', null, self::MODEL_BOTH, 'ignore'),
        array('password', 'think_ucenter_md5', self::MODEL_BOTH, 'function', WORKER_AUTH_KEY),
		array('birthday', '', self::MODEL_BOTH, 'ignore'),
		array('birthday', null, self::MODEL_BOTH, 'ignore'),
        array('birthday', 'GetMkTime', self::MODEL_BOTH, 'function'),
	);

	/**
     * 检测手机号码格式是否正确
     * @param  string $mobile 手机号
     * @return boolean          ture - 符合规范，false - 不符合规范
     * @author derek <693472824@qq.com>
     */
    protected function checkMobile($mobile){
        return preg_match("/^1[34578]\d{9}$/", $mobile);
    }

}